#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    char t,a[30];
    int book[37];
    int count,i,j,k,temp,flag;
    int kezi,jiang;
    while((scanf("%d",&n))!=EOF)
    {
    	getchar();
        scanf("%c",&t);getchar();
        while(n--)
        {
            memset(book,0,sizeof(book));
            count=1;flag=2;
            kezi=0;jiang=0;
            gets(a);
            for(i=0;a[i]!='\0';i+=2)
            {
                if(a[i+1] == t)
                    flag=1;
                temp=a[i]-'0';
                if(a[i+1]=='T')
                    book[temp]++;
                else if(a[i+1]=='S')
                    book[temp+9]++;
                else if(a[i+1]=='W')
                    book[temp+18]++;
            }
            for(i=1;i<=27;i++)
            {
                if(book[i]==3)
                    kezi++;
                if(book[i]==2)
                    jiang++;
            }
            if(flag==2)
            {
                if(kezi==0&&jiang==7)
                    printf("Yes\n");
                else if(kezi==4&&jiang==1)
                    printf("Yes\n");
                else
                    printf("No\n");
            }
            else if(flag==1)
            {
                if(kezi==4&&jiang==1)
                    printf("Yes\n");
                else
                    printf("No\n");
            }
        }
    }
    return 0;
}
